package com.aier.controller.purchase;

import com.aier.bean.common.CommonResult;
import com.aier.bean.purchase.GoodsArrivedBean;
import com.aier.service.purchase.GoodsArrivedService;
import com.aier.service.purchase.PurchaseService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.time.LocalDate;

/**
 * 到货表controller
 */

@Controller
public class GoodsArrivedController {
    @Resource
    private GoodsArrivedService goodsArrivedService;

    @Resource
    private PurchaseService purchaseService;

    @RequestMapping("/enter_goods_arrived")
    @ResponseBody
    public CommonResult enterProduct(@RequestBody GoodsArrivedBean goodsArrivedBean){
        purchaseService.contractCodeNotExist(goodsArrivedBean.getContractCode());
        purchaseService.isExistByContractCodeAndModelName(goodsArrivedBean.getContractCode(),goodsArrivedBean.getModelName());
        if (goodsArrivedBean.getArrivedDate() == null){
            goodsArrivedBean.setArrivedDate(LocalDate.now());
        }
        return goodsArrivedService.saveGoodsArrived(goodsArrivedBean);
    }
}
